package com.app.newiptv.helper;

import com.app.newiptv.bean.RequestDto;
import com.app.newiptv.bean.details.PlayDetailsBean;
import com.app.newiptv.callback.IRequestLisenter;
import com.app.newiptv.callback.RequestCallback;
import com.app.newiptv.utils.OkGoUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Shinelon on 2017/9/16.
 */

public class PalayDetailHelper {
    private RequestCallback callBack;
    private List<PlayDetailsBean> playDetailsBeanList;

    public PalayDetailHelper() {
        playDetailsBeanList = new ArrayList<>();
    }

    public void setCallback(RequestCallback callback) {
        this.callBack = callback;
    }

    //public void loadData(String url) {
    //
    //    OkGoUtil<PlayDetailsBean> okGoUtil = new OkGoUtil<PlayDetailsBean>(PlayDetailsBean.class, OkGoUtil.TYPE_ARRAY, new IRequestLisenter() {
    //        @Override
    //        public void onSuccessData(RequestDto dto) {
    //            playDetailsBeanList = (List<PlayDetailsBean>) dto.getList();
    //            if (callBack != null) {
    //                callBack.onLoadComplete("", 0, playDetailsBeanList.size(), playDetailsBeanList);
    //            }
    //        }
    //
    //        @Override
    //        public void onErrer(int code, String errMsg) {
    //        }
    //    });
    //    okGoUtil.requestGet(url);
    //}
    public void loadDetailsData(String url){
        OkGoUtil<PlayDetailsBean> okGoUtil = new OkGoUtil<PlayDetailsBean>(PlayDetailsBean.class, OkGoUtil.TYPE_DATA, new IRequestLisenter() {
            @Override
            public void onSuccessData(RequestDto dto) {
                PlayDetailsBean detailsBean = (PlayDetailsBean) dto.getData();
                playDetailsBeanList.add(detailsBean);
                if (callBack != null) {
                    callBack.onLoadComplete("", 0, 0, playDetailsBeanList);
                }
            }

            @Override
            public void onErrer(int code, String errMsg) {
            }
        });
        okGoUtil.requestGet(url);
    }
}
